<%
auth_session = session[:omniauth] || {}
auth_info = auth_session["info"] || {}
if auth_info
  resource.omniauth_provider = auth_session["provider"]
  resource.omniauth_uid = auth_session["uid"]

  resource.email = auth_info["email"] if resource.email.blank?
  resource.name = auth_info["name"] if resource.name.blank?
  if resource.slug.blank?
    resource.slug = auth_info["login"] || auth_info["name"]
  end
end
%>

<div class="col-12">
  <div class="heading text-center mb-4">
    <div class="f1 mb-2"><%= t(".Sign up") %></div>
    <div class="description text-gray-light f6"><%= t(".Welcome to use BlueDoc") %></div>
  </div>

  <% if auth_info.present? %>
  <div class="notice my-5">
    <p><%= t(".Complete your account info") %></p>
    <p><%= t(".You must complete the below form for sign up with_html", provider: BlueDoc::Utils.omniauth_camelize(resource.omniauth_provider)) %></p>
    <p><%= raw t(".If you had an exists BlueDoc account, you can sign in to bind account", link: link_to("Sign in", new_session_path(resource_name))) %></p>
  </div>
  <% end %>

  <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
    <% if auth_info.present? %>
      <%= f.hidden_field :omniauth_provider %>
      <%= f.hidden_field :omniauth_uid %>
      <%= f.hidden_field :name %>
    <% end %>

    <%= form_group(f, :slug) do %>
      <%= f.text_field :slug, autofocus: true, autocomplete: "username", class: "form-control" %>
    <% end %>

    <%= form_group(f, :name) do %>
      <%= f.text_field :name, autofocus: true, autocomplete: "name", class: "form-control" %>
      <div class="form-text">
        <%= t(".name help_html") %>
      </div>
    <% end %>

    <%= form_group(f, :email) do %>
      <%= f.email_field :email, autocomplete: "email", class: "form-control" %>

      <% if Setting.user_email_limit_enable? %>
      <div class="form-text user-email-suffix-support-list">
        <%= t(".Supported email suffix with list_html", emails: Setting.user_email_suffixes.join(", ")) %>
      </div>
      <% end %>
    <% end %>

    <%= form_group(f, :password) do %>
      <%= f.password_field :password, autocomplete: "new-password", class: "form-control" %>
    <% end %>

    <%= form_group(f, :password_confirmation) do %>
      <%= f.password_field :password_confirmation, autocomplete: "new-password", class: "form-control" %>
    <% end %>

    <% if rucaptcha_enable? %>
    <%= form_group(f, :base, label: false) do %>
      <label class="control-label"><%= t("Captcha") %></label>
      <%= rucaptcha_input_tag(class: 'form-control') %>
      <%= rucaptcha_image_tag(alt: 'Captcha') %>
    <% end %>
    <% end %>

    <div class="actions text-center mt-6">
      <%= f.submit t(".Sign up"), class: "btn btn-primary btn-full mb-3" %>
      <%= link_to t(".Already have a account"), new_session_path(resource_name), class: "f6 text-gray-light" %>
    </div>
  <% end %>
</div>


